package trafficAgent;

import jade.core.behaviours.OneShotBehaviour;

public class MasterBehaviour extends OneShotBehaviour {

	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	TrafficAgent agent; 
	
	static final int nStep = 6;
	
	public MasterBehaviour(final TrafficAgent myAgent) {
		super(myAgent);
		agent = myAgent;
	}
	
	
	@Override
	public void action() {
		
		final int step = agent.nextBehavStep(nStep);
		
		
		if(step == 0)
			if(!agent.isRunning())
				return;
		
		
		switch (step) {
		case 0:
			agent.addBehaviour(new RemoveGoalCars(agent));
			break;
		case 1:
			agent.addBehaviour(new AddRandomCar(agent));
			break;
		case 2:
			agent.addBehaviour(new ComputeBestRoute(agent));
			break;
		case 3:
			agent.addBehaviour(new MoveCars(agent));
			break;
		case 4:
			agent.addBehaviour(new CrossStreet(agent));
			break;
		case 5:
			agent.addBehaviour(new MoveCars(agent));
			break;

		default:
			break;
		}
		
		try {
			Thread.sleep(1000/nStep);
			agent.getThread().doRepaint();
		} catch (final InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}


}
